<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div>div</div>
<p>p</p>
<div>div</div>
<span>span</span>
<p>p</p>
<div>div</div>

<script>
    function select( selector ){
        var obj = document.querySelectorAll(selector);//伪数组

        obj.each = function (callback){
            each(this,callback);
        };
        return obj;
    }

    function each(arr,callback){
        for(var i=0;i<arr.length;i++){
            callback(arr[i],i);
        }
    }

    select('div,p').each(function(v)){
        v.style.border = '1px dashed blue';
    }
</script>
</body>
</html>